package com.kehao.newcoder;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NCSolution70 {
    private class ListNode {
        int val;
        ListNode next = null;
    }

    public ListNode sortInList(ListNode head) {
        // write code here
        List<Integer> list = new ArrayList<>();
        ListNode node = head;
        while (node!=null) {
            list.add(node.val);
            node = node.next;
        }
        Collections.sort(list);
        node = head;
        int i = 0;
        while (node!=null) {
            node.val = list.get(i++);
            node = node.next;
        }
        return head;
    }
}
